package com.manpower.web;

import com.manpower.common.Log;
import com.manpower.common.LogType;
import com.manpower.common.RestResponse;
import com.manpower.dao.dataobject.UserDto;
import com.manpower.service.TestUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("用户管理相关接口Controller")
@RequestMapping("/api")
@RestController
public class TestController {

    @Autowired
    private TestUserService testUserService;

    @ApiOperation("获取用户信息")
    @ApiImplicitParam(name = "id",value = "用户id",required = true,dataType = "int")
    @GetMapping("/getUser")
    public RestResponse getUser(Integer id){
        String user = testUserService.getUser(id);
        return  new RestResponse(user);

    }

    @ApiOperation("根据用户名称及地址获取用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName",value = "用户名称",required = true,dataType = "String"),
            @ApiImplicitParam(name = "addr",value = "用户地址",required = true,dataType = "String")

    })
    @GetMapping("/getUsers")
    @Log(type = LogType.Type1)
    public RestResponse getUser(String userName,String addr){
        List<UserDto> user2 = testUserService.getUser2(userName);
        return new RestResponse(user2);

    }

    @ApiOperation("获取用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页",required = false,dataType = "int"),
            @ApiImplicitParam(name = "limit",value = "当前页数量",required = false,dataType = "int")

    })
    @PostMapping("/postUserList")
    public RestResponse postUserList(UserDto userDto, @RequestParam(value="page",required = false,defaultValue="1") Integer page, @RequestParam(value="limit",required = false,defaultValue="10")Integer limit){
        return new RestResponse(testUserService.postUserList(userDto,page,limit));

    }


}
